#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int GetMaxValue(int* array, int nCnt)
{
    int nMax = array[0];

    for (int i = 1; i < nCnt; i++)
    {
        if (array[i] > nMax)
            nMax = array[i];
    }

    return nMax;
}
 
void sort(int* array, int nCnt)
{
    int nMax = GetMaxValue(array, nCnt);
    int k;

    int* lpBucket = (int*)malloc(sizeof(int) * (nMax + 1));
    if (!lpBucket) return;
    memset(lpBucket, 0, sizeof(int) * (nMax + 1));

    for (int i = 0; i < nCnt; i++)
        lpBucket[array[i]]++;

    k = 0;
    for (int i = 0; i <= nMax; i++)
    {
        while (lpBucket[i] != 0)
        {
            array[k] = i;
            k++;
            lpBucket[i]--;
        }
    }
}

int main()
{
    int array[9] = { 2,8,5,1,3,99,7,2,6 };

    sort(array, sizeof(array) / sizeof(int));

    for (unsigned int i = 0; i < (sizeof(array) / sizeof(int)); ++i)
        printf("%d ", array[i]);
    puts("");

    return 0;
}